#include<iostream>
#include<string>
#include<unordered_map>

class HttpResponse
{
    public:
    int _statu;
    bool _redirect_flag;
    std::string _body;
    std::string _redirect_url;
    std::unordered_map<std::string,std::string> _headers;

    public:
    HttpResponse():_redirect_flag(false),_statu(200){}

    HttpResponse(int statu):_redirect_flag(false),_statu(statu){}

    void ReSet()
    {
        _statu=200;
        _redirect_flag=false;
        _body.clear();
        _redirect_url.clear();
        _headers.clear();
    }

    void SetHeader(const std::string &key,const std::string &val)
    {
        _headers.insert(std::make_pair(key,val));
    }

    //判断是否存在指定的头部字段

    bool HasHeader(const std::string &key)const
    {
        auto it=_headers.find(key);
        if(it==_headers.end())
        {
            return false;
        }
        return true;
    }

    std::string GetHeader(const std::string &key)const{
        auto it=_headers.find(key);
        if(it==_headers.end())
        {
            return "";
        }
        return it->second;
    }

    void SetContent(const std::string body,const std::string &type="text/html")
    {
        _body=body;
        SetHeader("Content_Type",type);
    }

    void SetRedirect(const std::string &url,int statu=302)
    {
        _statu=statu;
        _redirect_flag=true;
        _redirect_url=url;
    }

    bool Close()
    {
        if(HasHeader("Contention")==true&&GetHeader("Contention")=="keep-alive")
        {
            return false;
        }
        return true;
    }


};